%%
linewidth=1;
Un_Trace_SegmentArrayIndex={''};
MgOColumn = find(strcmp('MgO',PetrogenMajorElement_Strings_Extracted));

comparisonData = 'off';



%%
PfracXtal=3;
YKGcharNF='-';
YKGcharPool='-';
YKGcharNF_instant='-.';
YKGcolor='fuschia';%layerplot_color_here_fill

FC_linewidth_IM=1; 
FC_linewidth_PM=3; 

targetStrings_Isotopes = {'SR87_SR86'	'ND143_ND144'	'PB206_PB204'	'PB207_PB204'	'PB208_PB204'	'HF176_HF177' 'TH230_U238_ACTIVITY' 'TH230_TH232_ACTIVITY' 'U238_TH232_ACTIVITY' 'RA226_TH230_ACTIVITY'};


galeon='yes';

%%
figure(1)
close
figure(1)
hold on
set(gcf, 'Units', 'Inches', 'Position', [1.8611 2.7778 8.5 11], 'PaperUnits', 'Inches', 'PaperSize', [8.5, 11])

FigureTitle = 'MajorTraceIso';
set(gcf,'name',regexprep(FigureTitle,'\_*',''))
numcolumns = 2;
numrows = 3;


positions=[1 2 4];


IndiciesFig1_X = {...
    'CaO'  'FeO' 'FeO'};

IndiciesFig1_Y = {...
    'MgO'  'MgO' 'Na2O'};


axesMajors = [8 15 5.5 15; 7.5 12 5.5 15; 7.5 12 1 4];



IndiciesX = upper(IndiciesFig1_X);
IndiciesY = upper(IndiciesFig1_Y);



for kk = 1:size(IndiciesX,1)
    for n = 1:size(IndiciesX,2)
        
        yyvalue =  IndiciesY(kk,n);
        xxvalue = IndiciesX(kk,n);
        
        [a,xxvalue]=(ismember(xxvalue, upper(PetrogenMajorElement_Strings_Extracted)));
        [a,yyvalue]=(ismember(yyvalue, upper(PetrogenMajorElement_Strings_Extracted)));
        
        
        subaxis(numrows,numcolumns,positions(n),...
            'SpacingHoriz',.06,'SpacingVert',.06,...
            'Margin',0,'MarginTop',.02,'MarginBottom',0,...
            'MarginBottom',.05,'MarginRight',.2,'MarginLeft',0.06,...
            'Padding',0.00,'PaddingLeft',.02,'PaddingBottom',.004)
        
        
        [Xtext,Ytext,FigureTitle] = oxideLabel(xxvalue,yyvalue);
        xlabel([Xtext,' (wt%)'])
        ylabel([Ytext,' (wt%)'])
        
        
        accumulatingLegend={};
        %         if n ==2
        %             %MgNum_all = [0.2 .4:.1:.8];
        %             MgNum_all = [.5 .6 .70 .72];
        %             plotMgNumContours(upper(Xtext),upper(Ytext),[4 20],[4 20],MgNum_all)
        %
        %         end
        %
        
        % axis(axesMajors(n,:))
        hold on
        axis square
        
        
        
        if strcmp(galeon,'yes')
            plot(Galeetal2013_Glasses(:,xxvalue), Galeetal2013_Glasses(:,yyvalue) ,'o','Color',grey8,'LineWidth',0.1,'MarkerSize',2,'MarkerFaceColor',grey8);% GALA14 517	Galapagos
            plot(Galeetal2013_MajorTrace(emorbs1,xxvalue), Galeetal2013_MajorTrace(emorbs1,yyvalue) ,'o','Color',grey5,'LineWidth',0.1,'MarkerSize',2,'MarkerFaceColor',grey5);% GALA14 517	Galapagos
            plot(Galeetal2013_Avg(:,xxvalue), Galeetal2013_Avg(:,yyvalue) ,'xk','Color',black,'LineWidth',3,'MarkerSize',15,'MarkerFaceColor',black);% GALA14 517	Galapagos
            
            accumulatingLegend={accumulatingLegend{:} 'all MORB' 'E-MORB' 'Average E-,N-,D- MORB'};
        end
        
        
        if strcmp(comparisonData,'on')==1
            for zz = UniqueLabels_Rows'
                i =find(ismember(runningLabels, runningLabels(zz)));
                
                plot(runningMajors(i,xxvalue),runningMajors(i,yyvalue),...
                    runningMarkers{zz},'LineWidth',0.5,'MarkerSize',eval(runningSizes{zz}), 'Color',eval(runningColors_LINE{zz}),...
                    'MarkerFaceColor',eval(runningColors_FILL{zz}),'HandleVisibility','on')
                
            end
            legendkey= {UniqueLabel2{:}};
            accumulatingLegend={accumulatingLegend{:} legendkey{:}};
        end
        
        
        for iik=1:numberModels
            layerplot_color_here = eval(char(layerplot_color(iik)));
            layerplot_color_here_fill = eval(char(layerplot_color_fill(iik)));
            FCLineColors_here = eval(char(FCLineColors(iik)));
            mymarkersize = layerplot_markersize(iik);
            layerplot_marker_here = char(layerplot_marker(iik));
            layerplot_color_here_edge = eval(char(layerplot_color_edge(iik)));
            
            
            
            [Xtextyy,Ytextxx] = oxideLabel(xxvalue,yyvalue);
            
            if any((strfind(TabNames{iik},'SM')))==1
                LegendModelcounter=1;
                
                numdatapts = size(eval(sprintf('%s(:,%g)', TabNames{iik}, xxvalue)),1);
                layerplot_marker_here = SM_Markers;
                
                
                
                for lll = 1:numdatapts
                    
                    mymarkersize = SM_MarkerSize(lll) ;
                    
                    if ismember(lll,whichPrimarySM2plot)
                        if LegendModelcounter==1
                            LegOnOff = 'on';
                        else
                            LegOnOff = 'off';
                        end
                        
                        
                        plot(eval(sprintf('%s(lll,%g)', TabNames{iik}, xxvalue)),eval(sprintf('%s(lll,%g)', TabNames{iik}, yyvalue)),...
                            char(layerplot_marker_here(lll)),'Color',layerplot_color_here,'MarkerFaceColor',layerplot_color_here_fill,...
                            'LineWidth',1,'MarkerSize',mymarkersize,'handlevisibility',LegOnOff)
                        LegendModelcounter=LegendModelcounter+1;
                    end
                end
                
                accumulatingLegend={accumulatingLegend{:} names4legend_all_sources{iik}};
            else
                
                plot(eval(sprintf('%s(:,%g)', TabNames{iik}, xxvalue)),eval(sprintf('%s(:,%g)', TabNames{iik}, yyvalue)),layerplot_marker_here,...
                    'Color',layerplot_color_here,'MarkerFaceColor',layerplot_color_here_fill,...
                    'LineWidth',1,'MarkerSize',mymarkersize)
                
                accumulatingLegend={accumulatingLegend{:} names4legend_all_sources{iik}};
                
            end
            
        end
        
        
        if isempty(NamesForFC) ==0
            for kjm = 1:size(NamesForFC,2)
                
                goodTabNames2=NamesForFC(kjm);
                [a2,b2]=find(ismember(TabNames,goodTabNames2));
                
                
                majorsHere = eval(sprintf('%s', TabNames{b2}));
                
                
                traceHere = eval(sprintf('%s_Trace', TabNames{b2}));
                traceHere(:,44)= 0.*traceHere(:,43);
                
                
                layerplot_color_here = eval(char(layerplot_color(b2)));
                layerplot_color_here_fill = eval(char(layerplot_color_fill(b2)));
                FCLineColors_here = eval(char(FCLineColors(b2)));
                
                
                linewidthFC = 1;
                
                for layerplotnumXX = whichFractionatedSM2plot
                    
                    clear testfrac testYYY
                    [testfrac,testXXX,testYYY] = YKG_wTRACE(majorsHere(layerplotnumXX,:),PetrogenMajorElement_Strings_Extracted,...
                        PfracXtal, traceHere(layerplotnumXX,:),Dmatrix);
                    f= [testfrac(:,MgOColumn)];
                    val = 6;
                    tmp = abs(f-val);
                    [idx idy] = min(tmp); %index of closest value
                    closest = idy;
                   
                    


                    if ismember(layerplotnumXX,[1 2 3])==1
                        plot(testfrac(1:closest,xxvalue), testfrac(1:closest,yyvalue),YKGcharNF,'Color',FCLineColors_here,'LineWidth',FC_linewidth_IM)
                    else if ismember(layerplotnumXX,[10 11])==1
                            plot(testfrac(1:closest,xxvalue), testfrac(1:closest,yyvalue),YKGcharPool,'Color',FCLineColors_here,'LineWidth',FC_linewidth_PM)
                        else if ismember(layerplotnumXX,[4 5 6])==1
                                plot(testfrac(1:closest,xxvalue), testfrac(1:closest,yyvalue),YKGcharNF,'Color',FCLineColors_here,'LineWidth',FC_linewidth_IM)
                            else if ismember(layerplotnumXX,[7 8 9])==1
                                    plot(testfrac(1:closest,xxvalue), testfrac(1:closest,yyvalue),YKGcharNF,'Color',FCLineColors_here,'LineWidth',FC_linewidth_IM)
                                    
                                end
                            end
                        end
                    end
                end
            end
        end
        
        
        
        
        
%         box on
%         ax = gca;
%         ax.XAxis.MinorTick = 'on';
%         increment = findBestIncrement( ax.XLim(2)- ax.XLim(1),ax.XAxis.TickValues(2) -  ax.XAxis.TickValues(1));
%         ax.XAxis.MinorTickValues = ax.XLim(1):increment:ax.XLim(2);
%         ax.YAxis.MinorTick = 'on';
%         increment = findBestIncrement( ax.YLim(2)- ax.YLim(1),ax.YAxis.TickValues(2) -  ax.YAxis.TickValues(1));
%         ax.YAxis.MinorTickValues = ax.YLim(1):increment:ax.YLim(2);
%         

    end
end



%%


axesMinors = [.6 7 .25 3.5
    ];


masterratiosX ={'Sm/Yb'};
masterratiosY ={'La/Sm'};


Xticks = {[ .4 .8 1:1:8 10 12]};


Yticks = {[0.05 0.2:.2:1 1.5 2 2.5 3:1:10];
    [0.5 1:1:5]};



logon = 1;
for n = 1
    
    subaxis(numrows,numcolumns,3)
    %axis(axesMinors(n,:))
    hold on
    axis square
    
    
    
    
    Desired_X=masterratiosX{n};
    Desired_Y=masterratiosY{n};
    [a,xxvalue] = ismember(Desired_X,RatioLabels);
    [b,yyvalue] = ismember(Desired_Y,RatioLabels);
    
    
  
    test1 = hline(1,'k-');
    test2=vline(1,'k-');
    uistack(test1,'bottom')
    uistack(test2,'bottom')
    

    
    if strcmp(galeon,'yes')==1
        plot(Galeetal2013_MajorTrace_DataRatios(:,xxvalue)./TraceElements4Normalization_DataRatios(xxvalue),...
            Galeetal2013_MajorTrace_DataRatios(:,yyvalue)./TraceElements4Normalization_DataRatios(yyvalue)...
            ,'o','Color',grey8,'LineWidth',0.1,'MarkerSize',4,'MarkerFaceColor',grey8);
        
        
        plot(Galeetal2013_MajorTrace_DataRatios(emorbs1,xxvalue)./TraceElements4Normalization_DataRatios(xxvalue),...
            Galeetal2013_MajorTrace_DataRatios(emorbs1,yyvalue)./TraceElements4Normalization_DataRatios(yyvalue)...
            ,'o','Color',grey5,'LineWidth',0.1,'MarkerSize',4,'MarkerFaceColor',grey5);
        
        plot(Galeetal2013_Avg_DataRatios(:,xxvalue)./TraceElements4Normalization_DataRatios(xxvalue),...
            Galeetal2013_Avg_DataRatios(:,yyvalue)./TraceElements4Normalization_DataRatios(yyvalue),...
            'xk','LineWidth',3,'MarkerSize',15, 'Color',black,'MarkerFaceColor',black);

    end
    
    
    
    plot(kimberlites_DataRatios(:,xxvalue)./TraceElements4Normalization_DataRatios(xxvalue),kimberlites_DataRatios(:,yyvalue)./TraceElements4Normalization_DataRatios(yyvalue)...
        ,'o','Color','r','LineWidth',0.1,'MarkerSize',3,'MarkerFaceColor','r','handlevisibility','off');
    
    if strcmp(comparisonData,'on')==1
        for zz = UniqueLabels_Rows'
            i =find(ismember(runningLabels, runningLabels(zz)));
            
            plot(RawTraceDataRatios(i,xxvalue)./DataRatios_TraceElements4Normalization(normalizationColumn,xxvalue),...
                RawTraceDataRatios(i,yyvalue)./DataRatios_TraceElements4Normalization(normalizationColumn,yyvalue),...
                runningMarkers{zz},'LineWidth',0.5,'MarkerSize',eval(runningSizes{zz}), 'Color',eval(runningColors_LINE{zz}),'MarkerFaceColor',eval(runningColors_FILL{zz}),'HandleVisibility','on')
            
        end
    end
    
    
    
    
    for iik=1:numberModels
        
        layerplot_color_here = eval(char(layerplot_color(iik)));
        layerplot_color_here_fill = eval(char(layerplot_color_fill(iik)));
        FCLineColors_here = eval(char(FCLineColors(iik)));
        mymarkersize = layerplot_markersize(iik);
        layerplot_marker_here = char(layerplot_marker(iik));
        layerplot_color_here_edge = eval(char(layerplot_color_edge(iik)));
        
        
        if any((strfind(TabNames{iik},'SM')))==1
            numdatapts = size(eval(sprintf('DataRatios_%s(:,%g)', TabNames{iik}, xxvalue)),1);
            layerplot_marker_here = SM_Markers;
            
            mymarkersizeSpecial = 3;
            for lll = 1:numdatapts
                if ismember(lll,whichPrimarySM2plot)
                    mymarkersize = SM_MarkerSize(lll) ;
                    plot(eval(sprintf('DataRatios_%s(lll,%g)', TabNames{iik}, xxvalue))./TraceElements4Normalization_DataRatios(xxvalue),eval(sprintf('DataRatios_%s(lll,%g)', ...
                        TabNames{iik}, yyvalue))./TraceElements4Normalization_DataRatios(yyvalue),char(layerplot_marker_here(lll)),...
                        'Color',layerplot_color_here,'MarkerFaceColor',layerplot_color_here_fill,'LineWidth',linewidth,'MarkerSize',mymarkersize,'HandleVisibility','off')
                    
                    
                    
                end
            end
        else
            
       
            plot(eval(sprintf('DataRatios_%s(:,%g)', TabNames{iik}, xxvalue))./TraceElements4Normalization_DataRatios(xxvalue),eval(sprintf('DataRatios_%s(:,%g)', TabNames{iik}, yyvalue))./TraceElements4Normalization_DataRatios(yyvalue),...
                layerplot_marker_here,...
                'Color',layerplot_color_here,'MarkerFaceColor',layerplot_color_here_fill,'MarkerEdgeColor',layerplot_color_here_edge,...
                'LineWidth',layerplot_linewidth(iik),'MarkerSize',mymarkersize);
            
            
        end
    end
    
    
    colorindex = 1;
    for iiill = 1% suball
        %indexforlenged(iii) = RidgesListIndex{iii}(1);
        clear datasmoosh;
        for jjj=1:size(Un_Trace_SegmentArrayIndex{iiill},2) %160;%
            plot(DataRatios_GALEsheet(unique_idx_trace{Un_Trace_SegmentArrayIndex{iiill}(jjj)},xxvalue)./TraceElements4Normalization_DataRatios(xxvalue),...
                DataRatios_GALEsheet(unique_idx_trace{Un_Trace_SegmentArrayIndex{iiill}(jjj)},yyvalue)./TraceElements4Normalization_DataRatios(yyvalue),...
                'o', 'color','k', 'markerfacecolor',colorsjetTrace(colorindex,:),'markersize',5) % GALA14 517	Galapagos
            % 'o', 'color',grey5, 'markerfacecolor',white,'markersize',8,'HandleVisibility','off') % GALA14 517	Galapagos
            
            %mostprimitivesmoosh = MostPrimitiveGaleDataIndex(RidgesListIndex{iii});
            %plot(MostPrimitiveGaleData(RidgesListIndex{iii}(jjj),yyvalue), MostPrimitiveGaleData(RidgesListIndex{iii}(jjj),i),'p', 'color',colorsjet(colorindex,:), 'markerfacecolor',colorsjet(colorindex,:),'markersize',10) % GALA14 517	Galapagos
            colorindex = colorindex+1;
        end
    end
    
    
    
    
 
    plot(DataRatios_MK91_TraceElements4Normalization(xxvalue)./TraceElements4Normalization_DataRatios(xxvalue),...
        DataRatios_MK91_TraceElements4Normalization(yyvalue)./TraceElements4Normalization_DataRatios(yyvalue),...
        'sk','LineWidth',1,'MarkerSize',8, 'Color',black,'MarkerFaceColor','none','handlevisibility','off');
    
    text(DataRatios_MK91_TraceElements4Normalization(xxvalue)./TraceElements4Normalization_DataRatios(xxvalue)-.03,...
        DataRatios_MK91_TraceElements4Normalization(yyvalue)./TraceElements4Normalization_DataRatios(yyvalue),...
        'MO','FontName','Times New Roman','HorizontalAlignment','right');
    
    %             plot(DataRatios_HSDM_TraceElements4Normalization(xxvalue)./TraceElements4Normalization_DataRatios(xxvalue),...
    %                 DataRatios_HSDM_TraceElements4Normalization(yyvalue)./TraceElements4Normalization_DataRatios(yyvalue),...
    %                 'sk','LineWidth',1,'MarkerSize',10, 'Color',black,'MarkerFaceColor',black,'handlevisibility','off');
    %xline(DataRatios_HSDM_TraceElements4Normalization(xxvalue)./TraceElements4Normalization_DataRatios(xxvalue),'k--','HS96','FontName','Times New Roman','LabelVerticalAlignment','bottom','LabelHorizontalAlignment','left');
    
    
    plot(DataRatios_Brown2020_TraceElements4Normalization(xxvalue)./TraceElements4Normalization_DataRatios(xxvalue),...
        DataRatios_Brown2020_TraceElements4Normalization(yyvalue)./TraceElements4Normalization_DataRatios(yyvalue),...
        'sk','LineWidth',1,'MarkerSize',8, 'Color','black','MarkerFaceColor','none','handlevisibility','off');
    
    text(DataRatios_Brown2020_TraceElements4Normalization(xxvalue)./TraceElements4Normalization_DataRatios(xxvalue)-.03,...
        DataRatios_Brown2020_TraceElements4Normalization(yyvalue)./TraceElements4Normalization_DataRatios(yyvalue),...
        'TS','FontName','Times New Roman','HorizontalAlignment','right');
    
    
    
    
    plot(DataRatios_TraceDMM(xxvalue)./TraceElements4Normalization_DataRatios(xxvalue),...
        DataRatios_TraceDMM(yyvalue)./TraceElements4Normalization_DataRatios(yyvalue),...
        'ko','LineWidth',1,'MarkerSize',12, 'Color',black,'MarkerFaceColor','none','handlevisibility','off');
    text(DataRatios_TraceDMM(xxvalue)./TraceElements4Normalization_DataRatios(xxvalue)-.04,...
        DataRatios_TraceDMM(yyvalue)./TraceElements4Normalization_DataRatios(yyvalue),...
        'WH','FontName','Times New Roman','HorizontalAlignment','right');
    
    plot(1,...
        1,...
        'ok','LineWidth',1,'MarkerSize',8, 'Color',black,'MarkerFaceColor','none','handlevisibility','off');
    text(1-.04,...
        1,...
        'PUM','FontName','Times New Roman','HorizontalAlignment','right');
    
    
    
    
    
    xlabel(sprintf('%s_{%s}',RatioLabels{xxvalue}, normalizationLabel));
    ylabel(sprintf('%s_{%s}',RatioLabels{yyvalue}, normalizationLabel));
    
    
   % box on
    
    
    if logon ==1
        set(gca,'yscale','log')
        set(gca,'xscale','log')
    end
    

end



%%
% QQQ

IndiciesFig1_X = {...
    'U'  'U'; ...
    };

IndiciesFig1_Y = {...
    'Na2O'  'Na2O'; ...
    };


Xticks = {[ .4 1 10 50];
    [0.1 1 10]};

Yticks = {[0.01 0.1 1 10 20];
    [0.5 1:.2:2 3]};

axesMinors = [.01 2 0 4.5];

Xticks=[.01  .1 1  2 3];
axesMajors = [.006 1 1 4; ...
    3 11 48 55  ;...
    ];

accumulatingLegend={};

IndiciesX = upper(IndiciesFig1_X);
IndiciesY = upper(IndiciesFig1_Y);

zza=1;
for kk = 1:size(IndiciesX,1)
    for n = 1:size(IndiciesX,2)
        
        
        
        xxvalueName = IndiciesX(kk,n);
        yyvalueName = IndiciesY(kk,n);
        
        
        [a,xxvalue]=(ismember(xxvalueName, upper(targetStrings_Trace)));
        [a,yyvalue]=(ismember(yyvalueName, upper(PetrogenMajorElement_Strings_Extracted)));
        
        
        
        
        subaxis(3,2,5)
        % axis(axesMajors(1,:))
        
        hold on
        axis square
        
        
        if strcmp(galeon,'yes')==1
            plot(Galeetal2013_MajorTrace_Trace(:,xxvalue),Galeetal2013_MajorTrace(:,yyvalue)...
                ,'o','Color',grey8,'LineWidth',0.1,'MarkerSize',2,'MarkerFaceColor',grey8);
            
            
            plot(Galeetal2013_MajorTrace_Trace(emorbs1,xxvalue),Galeetal2013_MajorTrace(emorbs1,yyvalue)...
                ,'o','Color',grey5,'LineWidth',0.1,'MarkerSize',2,'MarkerFaceColor',grey5);
            
            
            plot(Galeetal2013_Avg_Trace(:,xxvalue), Galeetal2013_Avg(:,yyvalue) ,...
                'xk','Color',black,'LineWidth',3,'MarkerSize',15,'MarkerFaceColor',black);% GALA14 517	Galapagos
            
            
            
            accumulatingLegend={accumulatingLegend{:} 'all MORB' 'E-MORB' 'Average E-, N-, D- MORB'};
            
        end
      
        if strcmp(comparisonData,'on')==1
            for zz = UniqueLabels_Rows'
                i =find(ismember(runningLabels, runningLabels(zz)));
                
                plot(runningTrace(i,xxvalue),...
                    runningMajors(i,yyvalue),...
                    runningMarkers{zz},'LineWidth',0.5,'MarkerSize',eval(runningSizes{zz}), 'Color',eval(runningColors_LINE{zz}),'MarkerFaceColor',eval(runningColors_FILL{zz}),'HandleVisibility','on')
                
            end
        end
        
        
        
        
        for iik=1:numberModels
            
  
            layerplot_color_here = eval(char(layerplot_color(iik)));
            layerplot_color_here_fill = eval(char(layerplot_color_fill(iik)));
            FCLineColors_here = eval(char(FCLineColors(iik)));
            mymarkersize = layerplot_markersize(iik);
            layerplot_marker_here = char(layerplot_marker(iik));
            layerplot_color_here_edge = eval(char(layerplot_color_edge(iik)));
            
            
            if any((strfind(TabNames{iik},'SM')))==1
                numdatapts = size(eval(sprintf('%s_Trace(:,%g)', TabNames{iik}, xxvalue)),1);
                layerplot_marker_here = SM_Markers;
                mymarkersizeSpecial = 3;
                
                LegendModelcounter=1;
                
                for lll = 1:numdatapts
                    if ismember(lll,whichPrimarySM2plot)
                        mymarkersize = SM_MarkerSize(lll) ;
                        
                        if LegendModelcounter==1
                            LegOnOff = 'on';
                        else
                            LegOnOff = 'off';
                        end
                        
                        
                        
                        plot(eval(sprintf('%s_Trace(lll,%g)', TabNames{iik}, xxvalue)),...
                            eval(sprintf('%s(lll,%g)', TabNames{iik}, yyvalue)),...
                            char(layerplot_marker_here(lll)),...
                            'Color',layerplot_color_here,'MarkerFaceColor',...
                            layerplot_color_here_fill,'LineWidth',linewidth,...
                            'MarkerSize',mymarkersize,'HandleVisibility',LegOnOff)
                        LegendModelcounter=LegendModelcounter+1;
                        
                        
                    end
                    accumulatingLegend={accumulatingLegend{:} names4legend_all_sources{iik}};
                end
            else
                
                
                plot(eval(sprintf('%s_Trace(:,%g)', TabNames{iik}, xxvalue)),...
                    eval(sprintf('%s(:,%g)', TabNames{iik}, yyvalue)),...
                    layerplot_marker_here,...
                    'Color',layerplot_color_here,'MarkerFaceColor',layerplot_color_here_fill,'MarkerEdgeColor',layerplot_color_here_fill,...
                    'LineWidth',linewidth,'MarkerSize',mymarkersize,'HandleVisibility','off');
                
                accumulatingLegend={accumulatingLegend{:} names4legend_all_sources{iik}};
            end
        end
        
        
        colorindex = 1;
        for iiill = 1% suball
            %indexforlenged(iii) = RidgesListIndex{iii}(1);
            clear datasmoosh;
            for jjj=1:size(Un_Trace_SegmentArrayIndex{iiill},2) %160;%
                plot(DataRatios_GALEsheet(unique_idx_trace{Un_Trace_SegmentArrayIndex{iiill}(jjj)},xxvalue)./TraceElements4Normalization_DataRatios(xxvalue),...
                    DataRatios_GALEsheet(unique_idx_trace{Un_Trace_SegmentArrayIndex{iiill}(jjj)},yyvalue)./TraceElements4Normalization_DataRatios(yyvalue),...
                    'o', 'color','k', 'markerfacecolor',colorsjetTrace(colorindex,:),'markersize',5) % GALA14 517	Galapagos
                % 'o', 'color',grey5, 'markerfacecolor',white,'markersize',8,'HandleVisibility','off') % GALA14 517	Galapagos
                
                %mostprimitivesmoosh = MostPrimitiveGaleDataIndex(RidgesListIndex{iii});
                %plot(MostPrimitiveGaleData(RidgesListIndex{iii}(jjj),yyvalue), MostPrimitiveGaleData(RidgesListIndex{iii}(jjj),i),'p', 'color',colorsjet(colorindex,:), 'markerfacecolor',colorsjet(colorindex,:),'markersize',10) % GALA14 517	Galapagos
                colorindex = colorindex+1;
            end
        end
        
        
        if isempty(NamesForFC) ==0
            for kjm = 1:size(NamesForFC,2)
                goodTabNames2=NamesForFC(kjm);
                
                [a2,b2]=find(ismember(TabNames,goodTabNames2));
                majorsHere = eval(sprintf('%s', TabNames{b2}));
                
                traceHere = eval(sprintf('%s_Trace', TabNames{b2}));
                traceHere(:,44)= 0.*traceHere(:,43);
                
                
                 layerplot_color_here = eval(char(layerplot_color(b2)));
                 layerplot_color_here_fill = eval(char(layerplot_color_fill(b2)));
                 FCLineColors_here = eval(char(FCLineColors(b2)));
               
                    
                
                for layerplotnumXX = whichFractionatedSM2plot
                    
                    
                    
                    clear testfrac testYYY
                    [testfrac,testXXX,testYYY] = YKG_wTRACE(majorsHere(layerplotnumXX,:),PetrogenMajorElement_Strings_Extracted, PfracXtal, traceHere(layerplotnumXX,:),Dmatrix);
                    
                    
                    f= [testfrac(:,MgOColumn)];
                    val = 6; %value to find
                    tmp = abs(f-val);
                    [idx idy] = min(tmp); %index of closest value
                    closest = idy;
                    
                    clear DataRatios
                    
                    
                    if ismember(layerplotnumXX,[1 2 3])==1
                        
                        plot(testXXX(1:closest,xxvalue),...
                            testfrac(1:closest,yyvalue),...
                            YKGcharNF,'Color',FCLineColors_here,'LineWidth',FC_linewidth_IM);
                        
                        
                    else if ismember(layerplotnumXX,[10 11])==1
                            
                            plot(testXXX(1:closest,xxvalue),...
                                testfrac(1:closest,yyvalue),...
                                YKGcharPool,'Color',FCLineColors_here,'LineWidth',FC_linewidth_PM);
                            
                            
                            
                        else if ismember(layerplotnumXX,[4 5 6])==1
                                
                                plot(testXXX(1:closest,xxvalue),...
                                    testfrac(1:closest,yyvalue),...
                                    YKGcharNF,'Color',FCLineColors_here,'LineWidth',FC_linewidth_IM);
                                
                            else if ismember(layerplotnumXX,[7 8 9])==1
                                    plot(testXXX(1:closest,xxvalue),...
                                        testfrac(1:closest,yyvalue),...
                                        YKGcharNF,'Color',FCLineColors_here,'LineWidth',FC_linewidth_IM);
                                    
                                    
                                end
                            end
                        end
                        
                        
                        
                    end
                end
            end
        end
        
        
        xlabel(sprintf('%s ppm',xxvalueName{:}));
        ylabel(sprintf('%s wt%',yyvalueName{:}));
        ylabel('Na_2O (wt%)');
        
        
        box on
        
        axis square
        set(gca,'ticklength',2*[0.0200    0.0500])
        %set(gca,'ticklength',2*get(gca,'ticklength'))
        set(gca,'fontsize', 17,'LineWidth',0.7,'FontName','Times New Roman')
        set(gca,'XColor', 'k')
        set(gca,'YColor', 'k')
        ax = gca;
        ax.XAxis.MinorTick = 'on';
        if logon ==1
            %set(gca,'yscale','log')
            set(gca,'xscale','log')
            set(gca, 'Xtick',unique([axesMinors(1:2) Xticks]))
            
            curtick = get(gca, 'XTick');
            set(gca, 'XTickLabel', cellstr(num2str(curtick(:))));
            
            ax.XAxis.MinorTickValues = [.001:.001:.01 .02:.01:.1 .2:.1:1 2:1:10];
            
        end
        
        %set(gca, 'Xtick',1500:10:1540)
        
        
        
        
        %         set(gca, 'Ytick',unique([axesMinors(n,3:4) Yticks{n}]))
        %         set(gca, 'Xtick',unique([axesMinors(n,1:2) Xticks{n}]))
        %
        %         curtick = get(gca, 'XTick');
        %         set(gca, 'XTickLabel', cellstr(num2str(curtick(:))));
        %         curtick = get(gca, 'YTick');
        %         set(gca, 'YTickLabel', cellstr(num2str(curtick(:))));
        %
        
        
        ax.YAxis.MinorTick = 'on';
        %     increment = findBestIncrement( ax.XLim(2)- ax.XLim(1),ax.XAxis.TickValues(2) -  ax.XAxis.TickValues(1));
        %  ax.XAxis.MinorTickValues = ax.XLim(1):increment:ax.XLim(2);
        %set(ax,'XMinorTick','on')
        
        %set(gca, 'Ytick',[.4 .6 .8  1 1.2 1.4  1.6 1.8 2 2.2 3 ])
        
        if strcmp(yyvalue,'NA2O')
            set(gca, 'Ytick',0:.5:10)
            increment = .25;
            ax.YAxis.MinorTickValues = ax.YLim(1):increment:ax.YLim(2);
        end
        
        
        
        % if n == 3
        %
        %    ax.YAxis.MinorTickValues = [[axesMinors(n,1):.001:.01] [.02:.1:3] ];%[2:1:axesMinors(n,2)]
        % end
    end
end

%%

IndiciesFig1_Y = {...
    'Na2O'
    };



IndiciesFig1_X = {...
    'TH230_U238_ACTIVITY'
    };


% axesMajors = [3 11 6 12; 3 11 48 55  ;...
%     3 11 .5 3 ; 3 11 15 21
%     3 11 7 12; 3 11 0.2 1.4];

IndiciesX = upper(IndiciesFig1_X);
IndiciesY = upper(IndiciesFig1_Y);


zza=1;

accumulatingLegend={};

for kk = 1:size(IndiciesX,1)
    for n = 1:size(IndiciesX,2)
        
        
        
        xxvalueName = IndiciesX(kk,n);
        [a,xxvalue]=(ismember(xxvalueName, upper(targetStrings_Isotopes)));
        
        yyvalueName =  IndiciesY(kk,n);
        [a,yyvalue]=(ismember(yyvalueName, upper(PetrogenMajorElement_Strings_Extracted)));
        
        
        subaxis(numrows,numcolumns,6)
        %axis([.9 1.9 1 4])
        hold on
        axis square
        
        
        if strcmp(comparisonData,'on')==1
            for zz = UniqueLabels_Rows'
                i =find(ismember(runningLabels, runningLabels(zz)));
                
                plot(RawIsotopes(i,xxvalue),...
                    runningMajors(i,yyvalue),...
                    runningMarkers{zz},'LineWidth',0.5,'MarkerSize',eval(runningSizes{zz}), 'Color',eval(runningColors_LINE{zz}),'MarkerFaceColor',eval(runningColors_FILL{zz}),'HandleVisibility','on')
                
            end
            accumulatingLegend={accumulatingLegend{:} legendkey{:}};
        end
        
        
        if strcmp(galeon,'yes')
            plot(Galeetal2013_MajorTrace_Isotopes(:,xxvalue), Galeetal2013_MajorTrace(:,yyvalue) ,'o','Color',grey8,'LineWidth',0.1,'MarkerSize',2,'MarkerFaceColor',grey8);% GALA14 517	Galapagos
            plot(Galeetal2013_MajorTrace_Isotopes(emorbs1,xxvalue), Galeetal2013_MajorTrace(emorbs1,yyvalue) ,'o','Color',grey5,'LineWidth',0.1,'MarkerSize',2,'MarkerFaceColor',grey5);% GALA14 517	Galapagos
            plot(Galeetal2013_Avg_Isotopes(:,xxvalue), Galeetal2013_Avg(:,yyvalue) ,'xk','Color',black,'LineWidth',3,'MarkerSize',15,'MarkerFaceColor',black);% GALA14 517	Galapagos
            
            accumulatingLegend={accumulatingLegend{:} 'all MORB' 'E-MORB' 'Average E-,N-,D- MORB'};
        end
        
         plot(kimberlites_Isotopes(:,xxvalue),kimberlites_DataRatios(:,yyvalue)./TraceElements4Normalization_DataRatios(yyvalue)...
        ,'o','Color','r','LineWidth',0.1,'MarkerSize',3,'MarkerFaceColor','r','handlevisibility','on');
        accumulatingLegend={accumulatingLegend{:} 'SA Kimberlites'};
        
        
        for iik=1:numberModels
            layerplot_color_here = eval(char(layerplot_color(iik)));
            layerplot_color_here_fill = eval(char(layerplot_color_fill(iik)));
            FCLineColors_here = eval(char(FCLineColors(iik)));
            mymarkersize = layerplot_markersize(iik);
            layerplot_marker_here = char(layerplot_marker(iik));
            layerplot_color_here_edge = eval(char(layerplot_color_edge(iik)));
            
            
            
            if any((strfind(TabNames{iik},'SM')))==1
                LegendModelcounter=1;
                
                numdatapts = size(eval(sprintf('%s(:,%g)', TabNames{iik}, 1)),1);
                layerplot_marker_here = SM_Markers;
                
                
                for lll = 1:numdatapts
                    
                    
                    mymarkersize = SM_MarkerSize(lll) ;
                    
                    if ismember(lll,whichPrimarySM2plot)
                        
                        if LegendModelcounter==1
                            LegOnOff = 'on';
                        else
                            LegOnOff = 'off';
                        end
                        
                        
                        
                        plot(eval(sprintf('%s_DISEQ(lll,1)', TabNames{iik})),eval(sprintf('%s(lll,%g)', TabNames{iik}, yyvalue)),...
                            char(layerplot_marker_here(lll)),...
                            'Color',classicrose,...
                            'MarkerFaceColor',layerplot_color_here_fill,...
                            'LineWidth',.5,....
                            'MarkerSize',mymarkersize,'handlevisibility',LegOnOff)
                        
                        plot(eval(sprintf('%s_DISEQ(lll,3)', TabNames{iik})),eval(sprintf('%s(lll,%g)', TabNames{iik}, yyvalue)),...
                            char(layerplot_marker_here(lll)),...
                            'Color',layerplot_color_here,...
                            'MarkerFaceColor',layerplot_color_here_fill,...
                            'LineWidth',.5,....
                            'MarkerSize',mymarkersize,'handlevisibility',LegOnOff)
                        
                        
                        LegendModelcounter=LegendModelcounter+1;
                    end
                end
                accumulatingLegend={accumulatingLegend{:} strcat('NEF-',names4legend_all_sources{iik}) strcat('LEF-',names4legend_all_sources{iik})};
            else
                
                plot(eval(sprintf('%s_DISEQ(:,1)', TabNames{iik})),eval(sprintf('%s(:,%g)', TabNames{iik}, yyvalue)),...
                    layerplot_marker_here,...
                    'Color',classicrose,...
                    'MarkerFaceColor',layerplot_color_here_fill,...
                    'MarkerEdgeColor',classicrose,...
                    'LineWidth',1,'MarkerSize',mymarkersize)
                
                
                plot(eval(sprintf('%s_DISEQ(:,3)', TabNames{iik})),eval(sprintf('%s(:,%g)', TabNames{iik}, yyvalue)),...
                    layerplot_marker_here,...
                    'Color',layerplot_color_here,...
                    'MarkerFaceColor',layerplot_color_here_fill,...
                    'MarkerEdgeColor',layerplot_color_here_fill,...
                    'LineWidth',1,'MarkerSize',mymarkersize)
                
                
                
                accumulatingLegend={accumulatingLegend{:} strcat('NEF-',names4legend_all_sources{iik}) strcat('LEF-',names4legend_all_sources{iik})};
            end
        end
        
        
        
        
        if isempty(NamesForFC) ==0
            for kjm = 1:size(NamesForFC,2)
                goodTabNames2=NamesForFC(kjm);
                [a2,b2]=find(ismember(TabNames,goodTabNames2));
                
                
                majorsHere = eval(sprintf('%s', TabNames{b2}));
                traceHere = eval(sprintf('%s_Trace', TabNames{b2}));
                traceHere(:,44)= 0.*traceHere(:,43);
                
                layerplot_color_here = eval(char(layerplot_color(b2)));
                layerplot_color_here_fill = eval(char(layerplot_color_fill(b2)));
                FCLineColors_here = eval(char(FCLineColors(b2)));
                linewidthFC = 1;
                LegendModelcounter=1;
                
                
                for layerplotnumXX = whichFractionatedSM2plot
                    
                    clear testfrac testYYY
                    [testfrac,testXXX,testYYY] = YKG_wTRACE(majorsHere(layerplotnumXX,:),PetrogenMajorElement_Strings_Extracted,PfracXtal, traceHere(layerplotnumXX,:),Dmatrix);
                    
                    f= [testfrac(:,MgOColumn)];
                    val = 6;
                    tmp = abs(f-val);
                    [idx idy] = min(tmp); %index of closest value
                    closest = idy;
                    
                    if LegendModelcounter==1
                        LegOnOff = 'on';
                    else
                        LegOnOff = 'off';
                    end
                    
                    
                    if ismember(layerplotnumXX,[1:9])==1
                        plot(eval(sprintf('%s_DISEQ(layerplotnumXX,3)', TabNames{b2})).*ones(closest,1), ...
                            testfrac(1:closest,yyvalue),YKGcharNF,'Color',...
                            FCLineColors_here,'LineWidth',FC_linewidth_IM,'handlevisibility',LegOnOff)
                        
                        plot(eval(sprintf('%s_DISEQ(layerplotnumXX,1)', TabNames{b2})).*ones(closest,1), ...
                            testfrac(1:closest,yyvalue),YKGcharNF_instant,'Color',...
                            FCLineColors_here,'LineWidth',FC_linewidth_IM,'handlevisibility',LegOnOff)
                        
                    else if ismember(layerplotnumXX,[10 11])==1
                            plot(eval(sprintf('%s_DISEQ(layerplotnumXX,3)', TabNames{b2})).*ones(closest,1), ...
                                testfrac(1:closest,yyvalue),'-',...
                                'Color',FCLineColors_here,...
                                'LineWidth',FC_linewidth_PM,'handlevisibility',LegOnOff)
                            
                            plot(eval(sprintf('%s_DISEQ(layerplotnumXX,1)', TabNames{b2})).*ones(closest,1), ....
                                testfrac(1:closest,yyvalue),...
                                YKGcharNF_instant,...
                                'Color',FCLineColors_here,...
                                'LineWidth',FC_linewidth_PM,'handlevisibility',LegOnOff)
                            
    
                        end
                        
                        
                    end
                    LegendModelcounter=LegendModelcounter+1;
                end
                legend2add = strcat('Ex.FC-',names4legend_all_sources{kjm});
                legend2add = regexprep(legend2add,'-IM','');
                legend2add = regexprep(legend2add,'-PM','');
                legend2add = regexprep(legend2add,'-SM','');
                accumulatingLegend={accumulatingLegend{:} strcat('NEF-',legend2add) strcat('LEF-',legend2add)};
            end
        end
        
        
        
        if n==1
            hleg = legend(accumulatingLegend);
        end
        
        
        %[Xtext,Ytext,FigureTitle] = oxideLabel(yyvalue,1);
        ylabel('Na_2O (wt%)');
        xlabel('(^{230}Th/^{238}U)');
        
        box on
        
        ax = gca;
        
        % increment = findBestIncrement( ax.XLim(2)- ax.XLim(1),ax.XAxis.TickValues(2) -  ax.XAxis.TickValues(1));
        % ax.XAxis.MinorTickValues = ax.XLim(1):0.05:ax.XLim(2);
        
        set(gca, 'Xtick',0:.2:5)
        ax.XAxis.MinorTick = 'on';
        ax.XAxis.MinorTickValues = 0:0.1:5;
        
        % ax.YAxis.MinorTick = 'on';
        % increment = findBestIncrement( ax.YLim(2)- ax.YLim(1),ax.YAxis.TickValues(2) -  ax.YAxis.TickValues(1));
        % ax.YAxis.MinorTickValues = ax.YLim(1):.05:ax.YLim(2);
        
        
        if strcmp(xxvalue,'NA2O')
            set(gca, 'Ytick',0:.5:10)
            increment = .25;
            
        end
        ax.YAxis.MinorTick = 'on';
        ax.YAxis.MinorTickValues = 0:increment:60;
        
        
        
        %set(gcf,'position',[2.7917 3.4306 9.7361 9.3750])
        % OPTION: uncomment for single (non-subplot plots)
        % legend(TabNames,'location','best')
        % title(FigureTitle)
        % FigureTitle = regexprep(FigureTitle,'\_*','');
        % FigureTitle = regexprep(FigureTitle,'\/','-');
        %         FigureTitle = 'Major_Isotope_ALL';
        %         set(gcf,'name',regexprep(FigureTitle,'\_*',''))
        
        %   if ismember(zz,[6])
        %        set(gca,'yscale','log')
        %   end
        zza=zza+1;
        
    end
end



%%



set(gcf,'name','Major_trace_isotope')
for n=1:numrows.*numcolumns
    subaxis(numrows,numcolumns,n)
    hold on
    box on
    axis square
    
    set(gca,'ticklength',2*[0.0200    0.0500])
    set(gca,'fontsize', 14,'LineWidth',.7,'FontName','Times New Roman')
    set(gca,'XColor', 'k')
    set(gca,'YColor', 'k')
    
    
    ax = gca;
    xlimits = xlim;
    ylimits = ylim;
    if xlimits(1)<0.2 && xlimits(1)~=0
        xlimits(1)=0.2;
    end
    if ylimits(1)<0.2 && ylimits(1)~=0
        ylimits(1)=0.2;
    end
    
    if strcmp(ax.YLabel.String,'Na_2O (wt%)')==1
        ylimits(2)=5;
    end
    
    
    if strcmp(ax.XLabel.String,'U ppm')==1
        xlimits(1)=0.005;
    end
    
    axis([round(xlimits, 2, 'significant') round(ylimits, 2, 'significant')]);
    
    
    if strcmp(ax.XScale,'linear')==1
        ax.XAxis.MinorTick = 'on';
        increment = findBestIncrement( ax.XLim(2)- ax.XLim(1),ax.XAxis.TickValues(2) -  ax.XAxis.TickValues(1));
        
        numIncre = (ax.XAxis.TickValues(2) -  ax.XAxis.TickValues(1))/increment;
        ax.XAxis.MinorTickValues = ax.XAxis.TickValues(1)-numIncre.*increment:increment:ax.XAxis.TickValues(end)+numIncre.*increment;
    else
        
        set(gca, 'Xtick',unique([[0.001 0.01 .1 1 10 100]]))
        
        curtick = get(gca, 'XTick');
        set(gca, 'XTickLabel', cellstr(num2str(curtick(:))));
        
        ax.XAxis.MinorTickValues = [.001:.001:.01 .02:.01:.1 .2:.1:1 2:1:10 20:10:100];
        
        
    end
    
    if strcmp(ax.YScale,'linear')==1
        ax.YAxis.MinorTick = 'on';
        increment = findBestIncrement( ax.YLim(2)- ax.YLim(1),ax.YAxis.TickValues(2) -  ax.YAxis.TickValues(1));
        
        
        numIncre = (ax.YAxis.TickValues(2) -  ax.YAxis.TickValues(1))/increment;
        ax.YAxis.MinorTickValues = ax.YAxis.TickValues(1)-numIncre.*increment:increment:ax.YAxis.TickValues(end)+numIncre.*increment;
    else
        
        set(gca, 'Ytick',unique([[0.001 0.01 .1 1 10 100]]))
        
        curtick = get(gca, 'YTick');
        set(gca, 'YTickLabel', cellstr(num2str(curtick(:))));
        
        ax.YAxis.MinorTickValues = [.001:.001:.01 .02:.01:.1 .2:.1:1 2:1:10 20:10:100];
        
        
    end
    
    
    
    subtitilesfix = {'A)' 'B)' 'C)' 'D)' 'E)' 'F)'} ;
    DataX = interp1( [0 1], xlim(), .01);
    DataY = interp1( [0 1], ylim(), .9 );
    
    text(DataX, DataY, subtitilesfix{(n)},'fontsize', 12,'FontName','Times New Roman')
    
    
end


runhere = eval(sprintf('%s_Info', goodTabNames{3}));
phihere = runhere(1,2).*100;
Tphere = runhere(1,4);
Waterhere = runhere(1,3);
Bulkhere = runhere(1,6);
'ZETA POOL percent'
ZETApool = runhere(1,13)*100
'Full Pool Crustal Thickness'
eval(sprintf('%s_Info(1,16)', goodTabNames{3}))

sourcehere= unique(layerplot_TESource);
meltmodelname=sprintf('%s=%.1f%% T_P=%d%sC %dppm H_2O \n Bulk#%d, %s','\phi',phihere,Tphere,'\circ',Waterhere,Bulkhere,sourcehere{:});
meltmodelname1 = '\it \phi=1% T_P=1300\circC 300ppm H_2O';
meltmodelname2 = '\it Bulk#17, WH DMM';

set(hleg,'Position',[0.8049 0.5114 0.5229 0.4590])
